#ifndef __LOG_HPP__
#define __LOG_HPP__

#include <iostream>
#include <string>
#include <log4cpp/Category.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/Priority.hh>
#include <log4cpp/Appender.hh>

using namespace std;
using namespace log4cpp;

class Mylogger
{
public:
    static Mylogger* getInstance();
    static void destroy();

private:
    Mylogger();
    ~Mylogger();
    static Mylogger* _pInstance;
    Category& _myCat;

};

Mylogger* Mylogger::_pInstance=getInstance();

Mylogger* Mylogger::getInstance()
{
    if(nullptr==_pInstance)
    {
        _pInstance=new Mylogger();
    }
    return _pInstance;
}

void Mylogger::destroy()
{
    if(_pInstance)
    {
        delete _pInstance;
        _pInstance=nullptr;
    }
}

Mylogger::Mylogger()
:_myCat(Category::getRoot().getInstance("myCat")) 
{
    PatternLayout* ppl=new PatternLayout();
    ppl->setConversionPattern("%d %c [%p] %m %n");
    FileAppender* pfa=new FileAppender("FileAppender","myCat.txt");
    pfa->setLayout(ppl);
    _myCat.addAppender(pfa);
    _myCat.setPriority(Priority::DEBUG);

}

Mylogger::~Mylogger()
{
    Category::shutdown();
}
#endif
